from selenium import webdriver
import logging
# 配置日志
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(lineno)d - %(levelname)s - %(message)s', filename='../log/login.log')
class Base:
    def __init__(self):  # 初始化操作
        self.driver = webdriver.Firefox()
        self.driver.maximize_window()
        self.driver.implicitly_wait(20)
        self.driver.get('http://127.0.0.1:8000/')
        logging.info('打开了浏览器')
    def base_find_element(self, loc):# 定位页面元素
        logging.info(f'定位了元素{loc}')
        return self.driver.find_element(*loc)
    def base_input(self, loc, value): # 输入
        logging.info(f'往元素{loc}中输入了{value}')
        el = self.base_find_element(loc)
        el.clear()
        el.send_keys(value)
    def base_click(self, loc): # 点击
        logging.info(f'点击了元素{loc}')
        self.base_find_element(loc).click()
    def base_get_text(self, loc): # 获取元素文本
        logging.info(f'获取了{loc}元素的文本')
        return self.base_find_element(loc).text
    def base_close(self): # 销毁
        logging.info('关闭了浏览器')
        self.driver.quit()
if __name__ == '__main__':
    b = Base()
    from time import sleep
    sleep(3)
    b.base_close()